package com.yztc.orangeentertainment.ui.main.subscribefragment.contentitem;

import android.content.Context;

import com.yztc.orangeentertainment.bean.starconbean.CategoryBean;
import com.yztc.orangeentertainment.config.SubscribeUrlConfig;
import com.yztc.orangeentertainment.http.SubscribeRetrofitService;

import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by My on 2016/10/10.
 * 订阅item Modle
 */
public class CategoryModle implements CategoryContract.Modle {

    @Override
    public void getCategoryAll(String type, Map<String, String> map, final OnLoadCategoryListener loadCategoryListener) {
        Retrofit retrofit=new Retrofit.Builder().baseUrl(SubscribeUrlConfig.PATH.BASE_URL).addConverterFactory(GsonConverterFactory.create()).build();
        Call<CategoryBean> call=retrofit.create(SubscribeRetrofitService.class).getSubCategoryAll(type,map);
        call.enqueue(new Callback<CategoryBean>() {
            @Override
            public void onResponse(Call<CategoryBean> call, Response<CategoryBean> response) {
                loadCategoryListener.onSuccess(response.body().getData());
            }

            @Override
            public void onFailure(Call<CategoryBean> call, Throwable t) {
                loadCategoryListener.onFailure((Exception) t);
            }
        });
    }
}